#!/bin/bash

# 判断是否已安装
if ! sed -n '/source ~/auto/vundle_plugin.vim/p' ~/.vimrc >/dev/null
then
    echo An error occurred
    exit 1
fi
res=$(sed -n '/source ~/auto/vundle_plugin.vim/p' ~/.vimrc | wc -l)
if [ $res = 1 ]; then
    echo Vunlde Plugin Installed
    exit
fi

# 从github安装
mkdir -p ~/.vim/bundle
git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim

cp ~/.vimrc vimrc.origin
cp vundle_plugin.origin.vim vundle_plugin.vim

# 插入文件头部 ~/.vimrc
echo '" Vunlde 插件管理器' >> temp_vundle_plugin
echo "source ~/auto/vundle_plugin.vim" >> temp_vundle_plugin
echo "" >> temp_vundle_plugin
cat temp_vundle_plugin ~/.vimrc > vimrc.temp

\rm -rf temp_vundle_plugin
mv vimrc.temp vimrc

ln -svf `pwd`/vimrc ~/.vimrc

vim +PluginInstall +qall

echo Vunlde Plugin Install Done.
